package com.malex.mxtracker.component;

import com.malex.mxtracker.MxTracker;
import com.malex.mxtracker.bean.Bank;
import com.malex.mxtracker.bean.Currency;
import com.malex.mxtracker.util.Utils;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import java.util.ArrayList;

/**
 * @author Manusovich Alexander
 */
public class BanksPanel extends Panel {
    public BanksPanel(String id) {
        super(id);
        createBanksGrid();
    }

    public void createBanksGrid() {
        final DataView<Bank> dataView = new DataView<Bank>("banksList",
                new ListDataProvider<Bank>(new ArrayList<Bank>(
                        MxTracker.getBanks().values()))) {
            public void populateItem(final Item item) {
                final Bank b = (Bank) item.getModelObject();
                item.add(new Label("name", b.getName()).setEscapeModelStrings(false));
                item.add(new Label("value", "" + b.getValue().intValue()).setEscapeModelStrings(false));
                item.add(new Label("currency", "" + b.getCurrency()).setEscapeModelStrings(false));
            }
        };
        add(dataView);
    }
}